package com.itheima.mapper;

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理
 */
@Mapper
public interface EmpMapper {
    /**
     * 记录数
     * @return
     */
//    @Select("select count(*) from emp where  name like concat('%',#{name},'%') and gender=#{gender} and entrydate between #{begin} and #{end}  ")
     Long count(String name,Short gender, LocalDate begin, LocalDate end);

    /**
     * 获取列表数据
     * @param start
     * @param pageSize
     * @return
     */
//    @Select("select *from emp where name like concat('%',#{name},'%') and gender=#{gender} and entrydate between #{begin} and #{end} order by update_time desc limit #{start},#{pageSize} ")
     List<Emp> page(Integer start, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end);

    /**
     * 批量删除
     * @param ids
     */
    void delete(List<Integer> ids);

    //新增员工
    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "VALUES (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime}) ")
    void addEmp(Emp emp);

    @Select("select *from emp where id=#{id}")
    Emp selectId(Integer id);

    /**
     * 更新员工
     * @param emp
     */
    void updata(Emp emp);

    @Select("select *from emp where username=#{username} and password=#{password}")
    Emp login(Emp emp);


    @Delete("delete from emp where dept_id=#{id}")
    void delete2(Integer id);
}
